# -*- encoding: utf-8 -*-
# @Author：lijinxi
# @Time ：2021/1/12 20:14
# @File：score_reform.py

# 按照结果重新计算分数
import csv

msgs = []
two_genes = []
with open('alignments_with_filed.txt', 'r', encoding='utf-8') as f:
    for line in f:
        line = line.strip().split('\t')
        key1, key2 = line[0:2]
        if key2 == key1:
            continue
        align_len, miss, gap = list(map(int, line[3:6]))
        msg = dict()
        msg['two genes'] = key1 + '_' + key2
        msg['align len'] = align_len
        msg['score'] = int(align_len * 10 - 5 * miss - 4 * gap)
        name = key1 + '_' + key2  # 避免重复
        if name not in two_genes:
            two_genes.append(name)
            msgs.append(msg)

with open('summary.csv', 'w', encoding='utf-8-sig', newline='') as f:
    fieldnames = msgs[0].keys()
    writer = csv.DictWriter(f, fieldnames=fieldnames)
    writer.writeheader()
    for msg in msgs:
        writer.writerow(msg)
